package com.kobe.manager.bidManager.service.impl;

import com.kobe.common.core.domain.AjaxResult;
import com.kobe.manager.bidManager.domain.Bid;
import com.kobe.manager.bidManager.mapper.BidMapper;
import com.kobe.manager.bidManager.service.IBidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BidServiceImpl implements IBidService {

    @Autowired
    private BidMapper bidMapper;
    @Override
    public List<Bid> selectBidList(Bid bid) {
        return bidMapper.selectBidList(bid);
    }

@Override
public AjaxResult add(Bid bid) {
    try {
        int result = bidMapper.add(bid);
        if (result > 0) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败");
        }
    } catch (Exception e) {
        return AjaxResult.error("添加失败：" + e.getMessage());
    }
}

@Override
public AjaxResult update(Bid bid) {
    try {
        int result = bidMapper.update(bid);
        if (result > 0) {
            return AjaxResult.success("修改成功");
        } else {
            return AjaxResult.error("修改失败");
        }
    } catch (Exception e) {
        return AjaxResult.error("修改失败：" + e.getMessage());
    }
}


    // 在 BidServiceImpl.java 中
    @Override
    public AjaxResult delete(Long[] ids) {
        try {
            int result = bidMapper.delete(ids);
            if (result > 0) {
                return AjaxResult.success("删除成功，共删除" + result + "条记录");
            } else {
                return AjaxResult.warn("未找到要删除的记录");
            }
        } catch (Exception e) {

            return AjaxResult.error("删除失败：" + e.getMessage());
        }
    }
}
